package org.come.Jpanel;


import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.XYBtn;
import com.tool.image.ImageMixDeal;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import com.tool.tcpimg.UIUtils;
import org.come.Frame.ZhuFrame;
import org.come.entity.RoleSummoning;
import org.come.until.CutButtonImage;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

public class XYXYDJpanel extends JPanel {
    public static XYBtn[] xiulian = new XYBtn[14];
    public List<String> tiaojian = new ArrayList<>();
    public XYBtn QICHENG;
    public XYBtn CHONGZHI;
    public static byte[] panduan = new byte[13];
    public static XYBtn chengsheng;
    public static XYBtn[] xinlu = new XYBtn[3];
    public static int xyxtX = 0;
    public static int xyxtY = 0;

    public static boolean QICHEN_CLICK = false;

    public XYXYDJpanel() {
        setPreferredSize(new Dimension(901, 548));
        setOpaque(false);
        setLayout(null);
        int offsetX = 40;
        int offsetY = 7;

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("skin/8100226/button/1.png", 1, 125);// 800 10
        offBtn.setBounds(800, 10, 25, 25);
        this.add(offBtn);

        xiulian[0] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 30, this,1);
        xiulian[0].setBounds(231+offsetX, 144-offsetY, 27, 27);

        //xiulian[0].setVisible(false);
        this.add(xiulian[0]);
        xiulian[1] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 31, this,1);
        xiulian[1].setBounds(198+offsetX, 233-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[1]);
        xiulian[2] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 32, this,1);
        xiulian[2].setBounds(108+offsetX, 137-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[2]);
        xiulian[3] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 33, this,1);
        xiulian[3].setBounds(145+offsetX, 292-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[3]);
        xiulian[4] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 34, this,1);
        xiulian[4].setBounds(185+offsetX, 395-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[4]);
        xiulian[5] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 35, this,1);
        xiulian[5].setBounds(259+offsetX, 286-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[5]);
        xiulian[6] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 36, this,1);
        xiulian[6].setBounds(348+offsetX, 220-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[6]);
        xiulian[7] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 37, this,1);
        xiulian[7].setBounds(431+offsetX, 127-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[7]);
        xiulian[8] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 38, this,1);
        xiulian[8].setBounds(534+offsetX, 96-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[8]);
        xiulian[9] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 39, this,1);
        xiulian[9].setBounds(568+offsetX, 149-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[9]);
        xiulian[10] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 40, this,1);
        xiulian[10].setBounds(587+offsetX, 205-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[10]);
        xiulian[11] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 41, this,1);
        xiulian[11].setBounds(643+offsetX, 266-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[11]);
        xiulian[12] = new XYBtn("skin/8100226/mouse/xy_btn0000.png", 1, 42, this,1);
        xiulian[12].setBounds(700+offsetX, 278-offsetY, 27, 27);
        //xiulian[0].setVisible(false);
        this.add(xiulian[12]);
        for (int k = 0; k <= xiulian.length - 1; k++) {
            if (k == 10) {
                xiulian[k].setBounds(xiulian[k].getX() - 2, xiulian[k].getY() - 5, 27, 27);
            } else if (xiulian[k] != null) {
                xiulian[k].setBounds(xiulian[k].getX() - 7, xiulian[k].getY() - 7, 27, 27);
            }
        }
        QICHENG = new XYBtn("skin/8100226/mouse/xyBigBtn.png", 1, 43, this, "确认加点");
        QICHENG.setBounds(410, 470, 80, 50);
//  this.add(QICHENG);

        xinlu[0] = new XYBtn("skin/8100226/button/心路1.png", 1, 44, this);
        xinlu[0].setBounds(803, 104, 37, 82);
        this.add(xinlu[0]);
        xinlu[1] = new XYBtn("skin/8100226/button/心意2.png", 1, 45, this);
        xinlu[1].setBounds(803, 184, 37, 82);
        this.add(xinlu[1]);

        xinlu[2] = new XYBtn("skin/8100226/button/心经2.png", 1, 18, this);
        xinlu[2].setBounds(803, 264, 37, 82);
        this.add(xinlu[2]);

        chengsheng = new XYBtn("skin/8100226/button/成圣按钮.png", 1, 444, this, "一念成圣");
        chengsheng.setBounds(395+offsetX, 400-offsetY, 104, 32);
        chengsheng.setVisible(false);
        this.add(chengsheng);

        xyQcLabel = new JLabel();
        xyQcLabel.setBounds(430, 450, 80, 50);
        // 打开抽奖
        xyQcLabel.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub
                if(XYXYDJpanel.QICHEN_CLICK){
                    return;
                }
                new Thread(() -> {
                    XYXYDJpanel.QICHEN_CLICK = true;
                    try {
                        for (int i = xldian; i < xiulian.length; i++) {
                            if(xiulian[i] != null){
                                if(check(xiulian[i].caozuo)){
                                    xiulian[i].nochoose(e);
                                    xyxtX = xiulian[i].getX();
                                    xyxtY = xiulian[i].getY();
                                    Thread.sleep(800L);
                                }else {
                                    break;
                                }
                            }
                        }
                        QICHENG.nochoose(e);
                        XYXYDJpanel.QICHEN_CLICK = false;
                    } catch (InterruptedException ex) {
                        throw new RuntimeException(ex);
                    }
                }).start();


            }
        });
        this.add(xyQcLabel);
    }

    private Boolean check(int x){
        RoleSummoning pet = UserMessUntil.getChosePetMes();
        int lvl = Integer.parseInt(XYBtn.changeGrade(pet.getGrade()).split("转")[1]);
        int grad = Integer.parseInt(XYBtn.changeGrade(pet.getGrade()).split("转")[0]);
        int num = 0;//高级技能个数
        int zhongji = 0;//终级技能
        int gezi = pet.getOpenSeal();
        int longgu = pet.getDragon();
        if (pet.getPetSkills()!=null){
            String[] skill = pet.getPetSkills().split("\\|");
            for (String m : skill) {
                int skinInt = Integer.parseInt(m);
                if (skinInt==1886||
                        skinInt==1887||
                        skinInt==1600||
                        skinInt==1601||
                        skinInt==1602||
                        skinInt==1603||
                        skinInt==1604||
                        skinInt==1605||
                        skinInt==1611||
                        skinInt==1612||
                        skinInt==1811||
                        skinInt==1815||
                        skinInt==1816||
                        skinInt==1817||
                        skinInt==1818||
                        skinInt==1819||
                        skinInt==1820||
                        skinInt==1821||
                        skinInt==1822||
                        skinInt==1823||
                        skinInt==1824||
                        skinInt==1825||
                        skinInt==1826||
                        skinInt==1827||
                        skinInt==1831||
                        skinInt==1833||
                        skinInt==1834||
                        skinInt==1835||
                        skinInt==1836||
                        skinInt==1837||
                        skinInt==1838||
                        skinInt==1839||
                        skinInt==1850||
                        skinInt==1852||
                        skinInt==1854||
                        skinInt==1858||
                        skinInt==1859||
                        skinInt==1860||
                        skinInt==1862||
                        skinInt==1864||
                        skinInt==1865||
                        skinInt==1871||
                        skinInt==1872||
                        skinInt==1873||
                        skinInt==1874||
                        skinInt==1875||
                        skinInt==1876||
                        skinInt==1877||
                        skinInt==1878||
                        skinInt==1879||
                        skinInt==1880||
                        skinInt==1882||
                        skinInt==1883||
                        skinInt==1884||
                        skinInt==1885)
                    num = num + 1;
            }
            for (String m : skill) {
                int skillInt = Integer.parseInt(m);
                if (skillInt==1606||
                        skillInt==1607||
                        skillInt==1608||
                        skillInt==1828||
                        skillInt==1829||
                        skillInt==1830||
                        skillInt==1840||
                        skillInt==1841||
                        skillInt==1842||
                        skillInt==1867||
                        skillInt==1868||
                        skillInt==1869
                )//判断ID啊 技能的ID
                    zhongji = zhongji + 1;
            }
        }

        switch (x-30) {

            case 0:
                if (lvl < 50) {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 1:
                if (pet.getFriendliness() < 100000) {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 2:
                if (lvl < 120 || pet.getFriendliness() < 200000) {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 3:
                if (lvl < 100 || grad < 2 || pet.getFriendliness() < 300000)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 4:
                if (lvl < 120 || grad < 2 || pet.getFriendliness() < 400000)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;

            case 5:
                if (lvl < 140 || gezi < 2)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 6:
                if (pet.getFriendliness() < 500000)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 7:
                if (num < 2 || grad < 3 || lvl < 140)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 8:
                if (pet.getFriendliness() < 1000000)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 9:
                if (num < 3 || pet.getFriendliness() < 2000000 || lvl < 160)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 10:
                if (gezi < 4 || pet.getFriendliness() < 4000000 || lvl < 170 || longgu < 1)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 11:
                if (gezi < 6 || pet.getFriendliness() < 6000000 || lvl < 175 || longgu < 3)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
            case 12:
                if (num < 4 || pet.getFriendliness() < 8000000 || lvl < 180 || zhongji < 2)//等级和亲密
                {
                    ZhuFrame.getZhuJpanel().addPrompt2("条件未满足！无法点亮新心路");
                    return false;
                }
                break;
        }


        return true;
    }


    private ImageIcon icon;

    static Sprite xybj = SpriteFactory.VloadSprite("skin/8100226/mouse/xybj", null);//特效路径

    static Sprite xyxl = SpriteFactory.VloadSprite("skin/8100226/mouse/xyxl", null);//心路

    Sprite xyqc = SpriteFactory.VloadSprite("skin/8100226/mouse/xyqc", null);//心猿启程

    private JLabel xyQcLabel;

    private ImageIcon xyxt = new ImageIcon("skin/8100226/button/心条.png");

    private ImageIcon xltx = new ImageIcon("skin/8100226/button/心路头像.png");

    private ImageIcon xyqctj = new ImageIcon("skin/8100226/mouse/xyqctj.png");
    private ImageIcon xybtn_2 = new ImageIcon("skin/8100226/mouse/xybtn_2.png");
    private ImageIcon hgs = new ImageIcon("skin/8100226/mouse/1-xy-hgs.png");
    private ImageIcon fc = new ImageIcon("skin/8100226/mouse/2-xy-fc.png");
    private ImageIcon lg = new ImageIcon("skin/8100226/mouse/3-xy-lg.png");
    private ImageIcon df = new ImageIcon("skin/8100226/mouse/4-xy-df.png");
    private ImageIcon tg = new ImageIcon("skin/8100226/mouse/5-xy-tg.png");
    private ImageIcon wzs = new ImageIcon("skin/8100226/mouse/6-xy-wzs.png");
    private ImageIcon dsjx = new ImageIcon("skin/8100226/mouse/7-xy-dsjx.png");

    private ImageIcon hg = new ImageIcon("skin/8100226/mouse/xy-hg.png");

    private ImageIcon ywc = new ImageIcon("skin/8100226/mouse/xy-ywc.png");

    private int O_Y1 = 330;
    private int O_Y2 = 360;
    private int O_Y3 = 390;
    private int O_Y4 = 420;

    static Sprite xycszl = SpriteFactory.VloadSprite("skin/8100226/mouse/xycszl", null);//特效路径

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        if(xybj != null){
            xybj.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xybj.draw(g, 0, 0);
        }

        if(xyxl != null){
            xyxl.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xyxl.draw(g, 105, 80);
        }

        g.drawImage(xyxt.getImage(), 805, 60, 26, 411, this);
        if (xyxtX != 0 && xyxtY != 0) {
            g.drawImage(xltx.getImage(), xyxtX - 18, xyxtY - 58, 51, 56, this);
        }else{
            double x = this.getXiulian()[0].getBounds().getX();
            double y = this.getXiulian()[0].getBounds().getY();
            xyxtX = (int)x;
            xyxtY = (int)y;
        }

        if(xycszl != null){
            xycszl.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xycszl.draw(g, 10, 50);
        }

        g.drawImage(xyqctj.getImage(), 333, 360, 20, 75, this);

        g.drawImage(xybtn_2.getImage(), xyxtX-5, xyxtY-1 , 28, 27, this);

        g.drawImage(hgs.getImage(), 260, 200 , 20, 60, this);

        g.drawImage(fc.getImage(), 110, 80 , 20, 60, this);

        g.drawImage(lg.getImage(), 145, 355 , 20, 40, this);

        g.drawImage(df.getImage(), 410, 230 , 20, 40, this);

        g.drawImage(tg.getImage(), 563, 110 , 20, 40, this);

        g.drawImage(wzs.getImage(), 610, 220 , 20, 60, this);

        g.drawImage(dsjx.getImage(), 740, 300 , 20, 75, this);

        if (xyqc != null) {
            xyqc.updateToTime(1, 0);
            xyqc.draw(g, 430, 450);
        }

//        g.drawRect(360, 355, 200, 95);
        g.setColor(new Color(192, 177, 100));
        g.setFont(UIUtils.TEXT_BOLD13);
        int k = 0;
        for (int p = 0; p <= panduan.length - 1; p++) {
            if (panduan[p] == 1)
                k = k + 1;
        }

        switch (k) {
            case 0:
                g.drawString("等级大于等于50级", 370, O_Y1);
                drawY1(g);
                break;
            case 1:
                g.drawString("亲密度大于等于10万点", 370, O_Y1);
                drawY1(g);
                break;
            case 2:
                g.drawString("等级大于等于120级", 370, O_Y1);
                drawY1(g);
                g.drawString("亲密度大于等于20万点", 370, O_Y2);
                drawY2(g);
                break;
            case 3:
                g.drawString("转生次数大于等于2次", 370, O_Y1);
                drawY1(g);
                g.drawString("等级大于等于100级", 370, O_Y2);
                drawY2(g);
                g.drawString("亲密度大于等于30万点", 370, O_Y3);
                drawY3(g);
                break;
            case 4:
                g.drawString("转生次数大于等于2次", 370, O_Y1);
                drawY1(g);
                g.drawString("等级大于等于120级", 370, O_Y2);
                drawY2(g);
                g.drawString("亲密度大于等于40万点", 370, O_Y3);
                drawY3(g);
                break;
            case 5:
                g.drawString("等级大于等于140级", 370, O_Y1);
                drawY1(g);
                g.drawString("开启技能格子数大于等于2个", 370, O_Y2);
                drawY2(g);
                break;
            case 6:
                g.drawString("亲密度大于等于50万点", 370, O_Y1);
                break;
            case 7:
                g.drawString("转生次数大于等于3次", 370, O_Y1);
                drawY1(g);
                g.drawString("等级大于等于140级", 370, O_Y2);
                drawY2(g);
                g.drawString("高级技能个数大于等于2个", 370, O_Y3);
                drawY3(g);
                break;
            case 8:
                g.drawString("亲密度大于等于100万点", 370, O_Y1);
                drawY1(g);
                break;
            case 9:
                g.drawString("等级大于等于160级", 370, O_Y1);
                drawY1(g);
                g.drawString("高级技能个数大于等于3个", 370, O_Y2);
                drawY2(g);
                g.drawString("亲密度大于等于200万点", 370, O_Y3);
                drawY3(g);
                break;
            case 10:
                g.drawString("等级大于等于170级", 370, O_Y1);
                drawY1(g);
                g.drawString("开启技能格子数大于等于4个", 370, O_Y2);
                drawY2(g);
                g.drawString("龙之骨数量大于等于1", 370, O_Y3);
                drawY3(g);
                g.drawString("亲密度大于等于400万点", 370, O_Y4);
                drawY4(g);
                break;
            case 11:
                g.drawString("等级大于等于175级", 370, O_Y1);
                drawY1(g);
                g.drawString("开启技能格子数大于等于6个", 370, O_Y2);
                drawY2(g);
                g.drawString("龙之骨数量大于等于3", 370, O_Y3);
                drawY3(g);
                g.drawString("亲密度大于等于600万点", 370, O_Y4);
                drawY4(g);
                break;
            case 12:
                g.drawString("等级大于等于180级", 370, O_Y1);
                drawY1(g);
                g.drawString("高级技能个数大于等于4个", 370, O_Y2);
                drawY2(g);
                g.drawString("终极技能个数大于等于2个", 370, O_Y3);
                drawY3(g);
                g.drawString("亲密度大于等于800万点", 370, O_Y4);
                drawY4(g);
                break;
        }
    }

    private void drawY4(Graphics g) {
        g.drawImage(hg.getImage(), 370, O_Y4+4 , 128, 4, this);
    }

    private void drawY3(Graphics g) {
        g.drawImage(hg.getImage(), 370, O_Y3+4 , 198, 4, this);
    }

    private void drawY2(Graphics g) {
        g.drawImage(hg.getImage(), 370, O_Y2+4 , 198, 4, this);
    }

    private void drawY1(Graphics g) {
        g.drawImage(hg.getImage(), 370, O_Y1+4 , 128, 4, this);
    }

    public static int xldian = 0;

    public static void CS(int k, String mes) {
        if (mes == null) {
            for (int i = 0; i <= getXiulian().length - 1; i++) {
                if (getXiulian()[i] != null) {
                    try {
                        getXiulian()[i].setIcons(CutButtonImage.cuts("skin/8100226/mouse/xy_btn0000.png"));
                        panduan[i] = 0;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            }
            chengsheng.setVisible(false);
            return;
        }

        String[] mes1 = mes.split("#");
        int m = k;
        if (mes1.length <= 2) {
            m = Integer.parseInt(mes1[1]);

        }
        for (int i = 1; i <= mes1.length - 2; i++) {
            if (mes1[i].equals("")) continue;
            try {
                m = m + 1;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        k = m;
        for (int i = k; i <= getXiulian().length - 1; i++) {
            if (getXiulian()[i] != null) {
                try {
                    getXiulian()[i].setIcons(CutButtonImage.cuts("skin/8100226/mouse/xy_btn0000.png"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
        double x = 0;
        double y = 0;
        for (int i = 0; i < k; i++) {
            if (i > getXiulian().length - 1) {
                continue;
            }
            if (getXiulian()[i] != null) {
                try {
                    getXiulian()[i].setIcons(CutButtonImage.cuts("skin/8100226/mouse/xy_xl_btn_5.png"));
                    x = getXiulian()[i].getBounds().getX();
                    y = getXiulian()[i].getBounds().getY();

                    XYXYDJpanel.panduan[i] = 1;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        xyxtX = (int) x;
        xyxtY = (int) y;
        xldian = k;
        if (k == 13)
            chengsheng.setVisible(true);
    }

    public static XYBtn[] getXiulian() {
        return xiulian;
    }

    public void setXiulian(XYBtn[] xiulian) {
        this.xiulian = xiulian;
    }

    public List<String> getTiaojian() {
        return tiaojian;
    }

    public void setTiaojian(List<String> tiaojian) {
        this.tiaojian = tiaojian;
    }

    public XYBtn getQICHENG() {
        return QICHENG;
    }

    public void setQICHENG(XYBtn QICHENG) {
        this.QICHENG = QICHENG;
    }

    public byte[] getPanduan() {
        return panduan;
    }

    public void setPanduan(byte[] panduan) {
        this.panduan = panduan;
    }


}
